﻿#ifndef XQACCOUNTARGS_H
#define XQACCOUNTARGS_H
#include<QString>
#include<QDateTime>
#include<QReadWriteLock>
//http账户的响应和回复的一些参数和用到的类整理
namespace HttpAccount
{
	const QByteArray UserTable = "User";//用户表
	namespace Head
	{
		//http字段常量的值
		//const QByteArray AppName = "Account";
		const QByteArray Login = "Login";//登录 
		const QByteArray Logout = "Logout";//登出 
		const QByteArray Register = "Register";//注册
		const QByteArray Info = "Info";//信息
		const QByteArray Portrait = "Portrait";//头像信息
		const QByteArray NewEmailVerify = "NewEmailVerify";//新邮箱验证码
		const QByteArray BindEmailVerify = "BindEmailVerify";//与账号绑定邮箱验证码 
		const QByteArray ModifyInfo = "ModifyInfo";//修改信息
		const QByteArray ModifyPassword = "ModifyPassword";//修改密码
		const QByteArray ModifyEmail = "ModifyEmail";//	修改邮箱
		//http字段常量
		const QByteArray App = "App";
		const QByteArray Error = "Error";
		const QByteArray Result = "Result";
		const QByteArray Command = "Command";
		const QByteArray Account = "Account";
		const QByteArray Type = "Type";
	}
	//错误
	enum Error
	{
		NoError,//无错误
		//UnconnectedServer,//服务器未连接
		NotLogin,//未登录
		ServerError,//服务器错误
		VerifyTimeout,//验证码超时
		VerifyTimeNotArrived,//验证码时间未到(更新)
		VerifyError,//验证码错误
		SendVerifyError,//发送验证码失败
		UnknownError,//未知错误
		AccountNotExist,//账户不存在
		AccountDuplicated,//账户重复了
		NewAccountFormatError,//新账户格式错误
		PasswordError,//密码错误
		NewPasswordFormatError,//新密码格式错误
		NewPasswordSameOld,//新密码与旧密码相同
		EmailError,//邮箱错误
		EmailBindOverboundCountError,//邮箱绑定数量超出限制了
		
	};
	Error toError(const QString& str);
	QByteArray error_toByteArray(Error e);
	QString error_toChinese(Error e);
	//结果
	enum Result
	{
		null,
		AccountLogin,//账号登录 
		AccountLogout,//账号登出 
		AccountRegister,//账号注册 
		AccountInfo,//账号信息
		AccountPortrait,//账号头像信息
		AccountNewEmailVerify,//账号 新邮箱验证码
		AccountBindEmailVerify,//账号 绑定邮箱验证码(账号与邮箱绑定的才可以发出验证码)
		AccountModifyPassword,//账号修改密码
		AccountModifyInfo,//账号修改信息
		AccountModifyEmail,//账号修改邮箱
	};
	Result toResult(const QString& str);
	QByteArray result_toByteArray(Result result);
	QString result_toChinese(Result result);
	class Verify
	{
	public:

	public:
		//是否可以刷新了
		bool isFlush();
		//是否有效
		bool isValid();
		QDateTime flushDateTime();
		QDateTime validDateTime();
		static int flushInterval();
		static int validInterval();
		//QReadWriteLock* lock();
		//获得验证码
		QString verify();
		//获得新的验证码(刷新验证码)
		virtual QString newVerify();
	public:
		//设置刷新间隔
		static void setFlushInterval(int msec);
		//设置有效间隔
		static void setValidInterval(int msec);
	protected:
		QString m_verify;//验证码
		QDateTime m_dateTime;//超时时间
		QReadWriteLock m_lock;//读写锁
		static int m_flushInterval;//刷新间隔时间
		static int m_validInterval;//有效间隔时间
	};
}

#endif // !
